//
//  TKTieziViewController.m
//  Ticket
//
//  Created by 小禹宝宝 on 2017/10/11.
//  Copyright © 2017年 cy55. All rights reserved.
//

#import "TKTieziViewController.h"
#import "BLBaseListViewDataController.h"
#import "TKmainShowTableViewCell.h"
#import "TKGoodsListResquest.h"
#import "TKTieziDetailViewController.h"
@interface TKTieziViewController ()
@property (nonatomic, strong) BLBaseListViewDataController *dataSource;

@end

@implementation TKTieziViewController

- (void)dealloc
{
    //    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    TKBasePageRequest *request = nil;
    /*
    if (self.listType != BLTieZiListTypeMine) {
        request = [BLCommunityListRequest new];
        [(BLCommunityListRequest *)request setType:self.listType];
    } else {
        self.title = @"我的帖子";
        request = [BLMyTiezListRequest new];
    }
     */
    TKGoodsListResquest *request = [TKGoodsListResquest new];
    request.category_id = self.listType;
//        [request setPage_flag:0];
//    [request setPage:1];
    _dataSource = [[BLBaseListViewDataController alloc] initWithRequest:request decodeClass:[TKGoodsListResponse class] afterParseCompletion:^(id responseObject) {
        DDLogInfo(@"responseObject ----:%@",responseObject);

        DDLogInfo(@"responseObject ---- list:%@",[(TKGoodsListResponse *)responseObject list]);
    }];
    
    self.listView.pagingListDataSource = _dataSource;
//    self.listView.estimatedRowHeight = 260;
//    self.listView.rowHeight = UITableViewAutomaticDimension;
    self.listView.rowHeight = 260;
    [self.listView registerNib:[UINib nibWithNibName:@"TKmainShowTableViewCell" bundle:nil] forCellReuseIdentifier:@"TKmainShowTableViewCell"];
//    [self.listView registerNib:[UINib nibWithNibName:@"BLCommunityVideoTableViewCell" bundle:nil] forCellReuseIdentifier:@"BLCommunityVideoTableViewCell"];
//    [self.listView registerNib:[UINib nibWithNibName:@"BLCommunityTextTableViewCell" bundle:nil] forCellReuseIdentifier:@"BLCommunityTextTableViewCell"];

}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listView.dataItems.count;
//    return 9;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TKmainShowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TKmainShowTableViewCell" forIndexPath:indexPath];
    TKGoodsItem *item = self.listView.dataItems[indexPath.row];
    cell.model = item;
    
    /*
    BLTiezi *item = self.listView.dataItems[indexPath.row];
    if (item.mode == 1) { //图片
        BLCommunityPicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BLCommunityPicTableViewCell" forIndexPath:indexPath];
        cell.type = self.listType;
        cell.model = item;
        return cell;
    } else if(item.mode == 2){ //视频
        BLCommunityVideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BLCommunityVideoTableViewCell" forIndexPath:indexPath];
        cell.type = self.listType;
        cell.model = item;
        return cell;
    } else {
        BLCommunityTextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BLCommunityTextTableViewCell" forIndexPath:indexPath];
        cell.type = self.listType;
        cell.model = item;
        return cell;
    }
     */
    return cell;
}

#pragma mark - UITableViewDelegate

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 80;
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TKGoodsItem *item = self.listView.dataItems[indexPath.row];
    TKTieziDetailViewController *detailVc = [TKTieziDetailViewController new];
    detailVc.goodsID = item.id;
    [KSNavi push:detailVc];
}


@end
